(function (_this) {
    if (typeof SiteConfig == "undefined") {
        SiteConfig = {}
    }
    
    console.log("siteConfig:",SiteConfig);

    _this.TemplateList = $.extend(true, _this.TemplateList, _this.ProjectTemplateList);
    _this.Component = {};
    //页面渲染
    _this.Page = function (options) {
        var __this = new Object();
        var __config = {
            componentList: [],//组件
            templateList: [],//模板
            fn: function () {

            }
        }
        var getTemplate = function (id, con) {
            var temp = null;
            if (_this.TemplateList[id]) {
                temp = _this.TemplateList[id]
            }
            if (con != undefined && con != '') {
                temp = con;
            }
            return temp;
        }
        var getComponentPath = function (id, isPage,baseDir) {
            var ComponentPath = '';
            var ComponentList = {
                Input: SiteConfig.ScriptRelativeUrl + 'Component/Input.jsx',
                Tree: SiteConfig.ScriptRelativeUrl + 'Component/Tree.jsx',
            }
            if (ComponentList[id]) {
                ComponentPath = ComponentList[id];
            } else {
                if (isPage) {
                	if(!!baseDir){
                		ComponentPath = SiteConfig.ViewUrl + baseDir +id + '.jsx';
                	}else{
                		ComponentPath = SiteConfig.ViewUrl + id + '.jsx';
                	}
                } else {
                    ComponentPath = SiteConfig.ScriptUrl + 'Component/' + id + '.jsx';
                }
            }
            return ComponentPath;
        }
        __this.Init = function (options) {
            __config = $.extend(true, __config, options);
            if (__config.templateList.length == 0) {
                __config.templateList = __config.componentList;
            }
            var requireList = [];
            if (__config.componentList.length > 0) {
                for (var i = 0; i < __config.componentList.length; i++) {
                    var str = "Frameweb/";
                    if (location.href.toLowerCase().indexOf("frameweb") >= 0) {
                        str = "";
                    }

                    if (typeof __config.componentList[i] == 'object') {
//                        requireList[i] = SiteConfig.FrameworkScriptUrl + "vui.2.0/plugin/require/text!" + getComponentPath(__config.componentList[i]['path'] || __config.componentList[i]['id'], __config.componentList[i]['isPage'],__config.componentList[i]['baseDir'])
                        requireList[i] = "text!" + getComponentPath(__config.componentList[i]['path'] || __config.componentList[i]['id'], __config.componentList[i]['isPage'],__config.componentList[i]['baseDir'])
                    }
                    if (typeof __config.componentList[i] == 'string') {
//                        requireList[i] = SiteConfig.FrameworkScriptUrl + "vui.2.0/plugin/require/text!" + getComponentPath(__config.componentList[i])
                        requireList[i] = "text!" + getComponentPath(__config.componentList[i])
                    }
                }
                
                //配置基础路径
                require.config({
                    paths:{
                        "text": SiteConfig.FrameworkScriptUrl+"vui.2.0/plugin/require/text",
                    }
                });
                require(requireList, function () {
                    for (var i = 0; i < arguments.length; i++) {
                        var id = __config.componentList[i];
                        if (typeof __config.componentList[i] == 'object') {
                            id = __config.componentList[i]["id"];
                        }
                        if (typeof __config.componentList[i] == 'string') {
                            id = __config.componentList[i];
                        }
                        var code = arguments[i];
                        code = Babel.transform(code, { presets: ["es2015", "react", "stage-2"] }).code;
                        code = code.replace('"use strict";', '').replace("'use strict';", '');
                        // console.log(code)
                        window.eval(code);
                    }
                    __config.fn();
                });
            }
        }
        __this.Render = function (options) {
            __config = $.extend(true, __config, options);
            if (__config.templateID == "") {
                __config.templateID = __config.componentID;
            }
            var code = '';
            var mountTemplate = getTemplate(__config.templateID, __config.template);
            code += 'const mountData = ' + JSON.stringify(__config.data) + ';'
                + ' const mountTemplate =' + mountTemplate + ';'
                + ' vui.Component["' + __config.componentID + '"] = ReactDOM.render(mountTemplate, document.querySelector("' + __config.id + '"));';
            code = Babel.transform(code, { presets: ["es2015", "react", "stage-2"] }).code;
            code = code.replace('"use strict";', '').replace("'use strict';", '');
            // console.log(code)
            window.eval(code);
        }
        return __this;
    }();
})(vui);
